package entity

import (
	"shqsoft.cn/pasnj/base"
	"time"

	"github.com/jinzhu/gorm"
)

//SJYHDR 国际结算量导入
type SJYHDR struct {
	ID    int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	KHYF  int       `gorm:"column:KHYF"`
	ZCSJH string    `gorm:"column:ZCSJH;"`
	KHMC  string    `gorm:"column:KHMC;"`
	ZJHM  string    `gorm:"column:ZJHM;"`
	ZCRQ  time.Time `gorm:"column:ZCRQ;"`
	KHJL  string    `gorm:"column:KHJL"`
}

//zgjhAfterImport 导入后执行
func sjyhAfterImport(tx *gorm.DB, params map[string]string) (err error) {
	err = tx.Exec("UPDATE T_BASE_YXFY_SJYH SET EMID=B.ID "+
		"FROM T_BASE_YXFY_SJYH A INNER JOIN T_SysUser B ON (A.KHJL=B.SysUserName) OR (A.KHJL=B.SysUserID)"+
		"WHERE KHYF=?", params["KHYF"]).Error
	if err != nil {
		return err
	}
	return nil
}

//TableName 国际中收导入表
func (SJYHDR) TableName() string {
	return "T_BASE_YXFY_SJYH"
}

//SJYHDREF 返回结构体
func SJYHDREF() base.EntityFunc {
	return func() interface{} {
		entity := SJYHDR{}
		return &entity
	}
}

//SJYHDRESF 返回结构体数组
func SJYHDRESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []SJYHDR
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("SJYHDR", base.NewDefaultDao(SJYHDREF(), SJYHDRESF(), nil))
	base.SetAfterCallBack("SJYHDR", sjyhAfterImport)

}
